package defpackage; import android.support.v4.app.NotificationCompat; import android.text.TextUtils; import android.util.Base64; import cn.wps.moffice.OfficeApp; import cn.wps.moffice_eng.R; import com.google.firebase.analytics.FirebaseAnalytics; import com.google.firebase.perf.FirebasePerformance; import com.google.gson.JsonObject; import com.iflytek.cloud.SpeechUtility; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.util.HashMap; import org.json.JSONException; import org.json.JSONObject; /* renamed from: gyb reason: default package */ public final class gyb { /* renamed from: gyb$a */ public interface a<T> { void Q(T t); } public static void a(final gxv gxv, final a<gxv> aVar) { if (gxv == null || TextUtils.isEmpty(gxv.id) || TextUtils.isEmpty(gxv.hIp)) { lvg.d(OfficeApp.arx(), R.string.documentmanager_qing_roamingdoc_no_network_operation_fail, 0); } else { new fcv<Void, Void, gxv>() { /* class defpackage.gyb.AnonymousClass3 */ private gxv bWu() { try { JSONObject jSONObject = new JSONObject(lwd.f(String.format("https://papercheck.wps.cn/api/v1/papers/%s/checks/%s/status", gxv.id, gxv.hIp), gyb.bWt())); gxv.status = jSONObject.optString(NotificationCompat.CATEGORY_STATUS); if ("checking".equals(gxv.status)) { gxv.hIx = 3; gxv.hIu = jSONObject.optLong("predict_end_time"); } else if ("transfering".equals(gxv.status)) { gxv.hIx = 2; gxv.hIu = jSONObject.optLong("predict_end_time"); } else if (FirebaseAnalytics.Param.SUCCESS.equals(gxv.status)) { gxv.hIx = 1; gxv.hIw = jSONObject.optJSONObject(SpeechUtility.TAG_RESOURCE_RESULT).optInt("repetitive_count"); gxv.hIv = jSONObject.optJSONObject(SpeechUtility.TAG_RESOURCE_RESULT).optDouble("repetitive_rate"); } else if ("failed".equals(gxv.status)) { gxv.hIx = -1; gxv.msg = jSONObject.optString(NotificationCompat.CATEGORY_MESSAGE); } } catch (IOException | JSONException e) { e.printStackTrace(); } return gxv; } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object[]] */ /* access modifiers changed from: protected */ @Override // defpackage.fcv public final /* synthetic */ gxv doInBackground(Void[] voidArr) { return bWu(); } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ /* access modifiers changed from: protected */ @Override // defpackage.fcv public final /* synthetic */ void onPostExecute(gxv gxv) { gxv gxv2 = gxv; if (aVar != null) { aVar.Q(gxv2); } } }.execute(new Void[0]); } } static void a(AutoCloseable autoCloseable) { if (autoCloseable != null) { try { autoCloseable.close(); } catch (Exception e) { e.printStackTrace(); } } } private static void a(HttpURLConnection httpURLConnection, File file) throws IOException { FileInputStream fileInputStream; DataOutputStream dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream()); try { fileInputStream = new FileInputStream(file); try { byte[] bArr = new byte[4096]; while (true) { int read = fileInputStream.read(bArr); if (read != -1) { dataOutputStream.write(bArr, 0, read); } else { dataOutputStream.flush(); a(fileInputStream); a(dataOutputStream); return; } } } catch (Throwable th) { th = th; a(fileInputStream); a(dataOutputStream); throw th; } } catch (Throwable th2) { th = th2; fileInputStream = null; a(fileInputStream); a(dataOutputStream); throw th; } } public static boolean b(File file, gxv gxv) { try { JSONObject jSONObject = new JSONObject(); jSONObject.put("document_name", Base64.encodeToString(gxv.hIz.getName().getBytes(), 11)); String aa = hnq.aa(file); jSONObject.put("document_md5", hnq.aa(gxv.hIz)); jSONObject.put("content_md5", aa); JSONObject jSONObject2 = new JSONObject(lwd.c("https://papercheck.wps.cn/api/v1/papers", jSONObject.toString(), bWt())); gxv.id = jSONObject2.getString("id"); gxv.hIn = jSONObject2.getString("document_url"); gxv.hIo = jSONObject2.getString("content_url"); return true; } catch (IOException | JSONException e) { e.printStackTrace(); return false; } } /* JADX WARNING: Removed duplicated region for block: B:19:0x0054 */ /* JADX WARNING: Removed duplicated region for block: B:22:0x005b */ public static boolean b(String str, File file) { Throwable th; HttpURLConnection httpURLConnection; Exception e; HttpURLConnection httpURLConnection2 = null; try { HttpURLConnection httpURLConnection3 = (HttpURLConnection) new URL(str).openConnection(); try { httpURLConnection3.setDoInput(true); httpURLConnection3.setDoOutput(true); httpURLConnection3.setRequestMethod(FirebasePerformance.HttpMethod.PUT); httpURLConnection3.setRequestProperty("x-amz-acl", "private"); httpURLConnection3.setRequestProperty("Content-Type", "application/ocet-stream"); a(httpURLConnection3, file); if (httpURLConnection3.getResponseCode() == 200) { if (httpURLConnection3 != null) { httpURLConnection3.disconnect(); } return true; } if (httpURLConnection3 != null) { httpURLConnection3.disconnect(); } return false; } catch (Exception e2) { httpURLConnection = httpURLConnection3; e = e2; try { e.printStackTrace(); lvg.d(OfficeApp.arx(), R.string.documentmanager_qing_roamingdoc_no_network_operation_fail, 0); if (httpURLConnection != null) { } return false; } catch (Throwable th2) { th = th2; httpURLConnection2 = httpURLConnection; if (httpURLConnection2 != null) { } throw th; } } catch (Throwable th3) { httpURLConnection2 = httpURLConnection3; th = th3; if (httpURLConnection2 != null) { } throw th; } } catch (Exception e3) { e = e3; httpURLConnection = null; e.printStackTrace(); lvg.d(OfficeApp.arx(), R.string.documentmanager_qing_roamingdoc_no_network_operation_fail, 0); if (httpURLConnection != null) { httpURLConnection.disconnect(); } return false; } catch (Throwable th4) { th = th4; if (httpURLConnection2 != null) { httpURLConnection2.disconnect(); } throw th; } } public static HashMap<String, String> bWt() { HashMap<String, String> hashMap = new HashMap<>(); hashMap.put("Cookie", "wps_sid=" + fok.bBq().getWPSSid()); hashMap.put("Client-Type", "wps-android"); hashMap.put("Client-Ver", OfficeApp.arx().getString(R.string.app_version)); hashMap.put("Client-Lang", eip.dHN); hashMap.put("Client-Chan", OfficeApp.arx().arA()); return hashMap; } public static gxv c(gxv gxv) { String format = String.format("https://papercheck.wps.cn/api/v1/papers/%s/uploaded", gxv.id); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("document", (Boolean) true); jsonObject.addProperty(FirebaseAnalytics.Param.CONTENT, (Boolean) true); try { gxv.hIr = new JSONObject(lwd.c(format, jsonObject.toString(), bWt())).getString("char_count"); return gxv; } catch (Exception e) { e.printStackTrace(); return null; } } }